package com.woniu.defecttracking.controller.bugs;


import com.woniu.defecttracking.annotation.AddNum;
import com.woniu.defecttracking.commens.Result;
import com.woniu.defecttracking.dto.BugTypeDto;
import com.woniu.defecttracking.dto.FindBugDto;
import com.woniu.defecttracking.param.FindBugParam;
import com.woniu.defecttracking.service.BugTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 何家欣
 * @since 2021-12-31
 */
@RestController
@RequestMapping("/bugType")
public class BugTypeController {

    @Autowired
    private BugTypeService bugTypeService;
    @PostMapping("/findAllBugInfo")
    public Result findAllBugInfo(){
        //返回全部状态的
        BugTypeDto bugInfo = bugTypeService.findAllBugInfo();
        if (bugInfo==null){
            return Result.getInstance(bugInfo).setMessage("查询失败").setCode(500).setData(bugInfo);

        }
        return Result.getInstance(bugInfo).setMessage("查询成功").setCode(200).setData(bugInfo);
    }
    @PostMapping("/findBugInfo")
    public Result findBugInfo(){
        //返回开启状态的
        FindBugDto bugInfo = bugTypeService.findBugInfo();
        if (bugInfo==null){
            return Result.getInstance(bugInfo).setMessage("查询失败").setCode(500).setData(bugInfo);

        }
        return Result.getInstance(bugInfo).setMessage("查询成功").setCode(200).setData(bugInfo);
    }

    @PostMapping("/addBugInfo")
    public Result addBugInfo(@RequestBody FindBugParam findBugParam){
        boolean b = bugTypeService.addBugInfo(findBugParam);
        if (b==false){
            return Result.getInstance(b).setMessage("添加失败").setCode(500).setData(b);

        }
        return Result.getInstance(b).setMessage("添加成功").setCode(200).setData(b);
    }

    @PostMapping("/updateBugInfo")
    public Result updateBugInfo(@RequestBody FindBugParam updateBug){
        boolean b = bugTypeService.updateBugInfo(updateBug);
        if (b==false){
            return Result.getInstance(false).setMessage("修改失败").setCode(500);

        }
        return Result.getInstance(true).setMessage("修改成功").setCode(200);
    }
    @PostMapping("/deleteBugInfo")
    public Result deleteBugInfo(@RequestBody List<Integer> ids){
        System.out.println(ids);
        boolean b = bugTypeService.deleteBugInfo(ids);
        if (b==false){
            return Result.getInstance(false).setMessage("删除失败").setCode(500);

        }
        return Result.getInstance(true).setMessage("删除成功").setCode(200);
    }

    //开启
    @GetMapping("/updateStatusUp/{id}")
    public Result updateStateUp(@PathVariable Integer id){
        boolean b = bugTypeService.updateStatusUp(id);
        if (b==false){
            return Result.getInstance(false).setMessage("开启失败").setCode(500);

        }
        return Result.getInstance(true).setMessage("开启成功").setCode(200);
    }
    //关闭
    @GetMapping("/updateStatusDown/{id}")
    public Result updateStateDown(@PathVariable Integer id){
        boolean b = bugTypeService.updateStatusDown(id);
        if (b==false){
            return Result.getInstance(false).setMessage("关闭失败").setCode(500);

        }
        return Result.getInstance(true).setMessage("关闭成功").setCode(200);
    }

}

